package com.zcxx.cotton.base;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zcxx.cotton.base.domain.PubPickerDevice;
import com.zcxx.cotton.base.service.IPubPickerDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 采棉机管理Controller
 *
 * @author ruoyi
 * @date 2021-09-23
 */
@RestController
@Api("采棉机管理")
@RequestMapping("/base/pickerDevice")
public class PubPickerDeviceController extends BaseController {

    @Autowired
    private IPubPickerDeviceService pubPickerDeviceService;




    /**
     * 查询采棉机管理列表
     */
    @ApiOperation("查询采棉机管理列表")
    @GetMapping("/list")
    public TableDataInfo list(PubPickerDevice pubPickerDevice) {
        startPage();
        List<PubPickerDevice> list = pubPickerDeviceService.selectPubPickerDeviceList(pubPickerDevice);
        return getDataTable(list);
    }


    /**
     * 查询全部采棉机管理列表
     */
    @GetMapping("/allList")
    public TableDataInfo allList(PubPickerDevice pubPickerDevice) {
        List<PubPickerDevice> list = pubPickerDeviceService.selectPubPickerDeviceList(pubPickerDevice);
        return getDataTable(list);
    }


    /**
     * 导出采棉机管理列表
     */

    @PostMapping("/export")
    public AjaxResult export(PubPickerDevice pubPickerDevice) {
        List<PubPickerDevice> list = pubPickerDeviceService.selectPubPickerDeviceList(pubPickerDevice);
        ExcelUtil<PubPickerDevice> util = new ExcelUtil<PubPickerDevice>(PubPickerDevice.class);
        return util.exportExcel(list, "采棉机管理数据");
    }


    /**
     * 新增保存采棉机管理
     */

    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody PubPickerDevice pubPickerDevice) {
        try {
            pubPickerDeviceService.save(pubPickerDevice);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.success();
    }

    /**
     * 修改采棉机管理
     */
    @GetMapping("/edit/{pickerCode}")
    public AjaxResult edit(@PathVariable("pickerCode") String pickerCode) {
        PubPickerDevice pubPickerDevice = pubPickerDeviceService.selectPubPickerDeviceById(pickerCode);
        return AjaxResult.success(pubPickerDevice);
    }

    /**
     * 修改保存采棉机管理
     */

    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody PubPickerDevice pubPickerDevice) {
        return toAjax(pubPickerDeviceService.updatePubPickerDevice(pubPickerDevice));
    }

    /**
     * 删除采棉机管理
     */

    @PostMapping("/remove")
    public AjaxResult remove(String ids) {
        return toAjax(pubPickerDeviceService.deletePubPickerDeviceByIds(ids));
    }


    /**
     * 状态修改
     */

    @PostMapping("/changeStatus")
    public AjaxResult changeStatus(PubPickerDevice pubPickerDevice) {

        return toAjax(pubPickerDeviceService.changeStatus(pubPickerDevice));
    }

    /**
     * 查询行政区域树列表
     */
    @PostMapping("/queryList")
    public List<PubPickerDevice> queryList(PubPickerDevice pubPickerDevice) {
        List<PubPickerDevice> list = pubPickerDeviceService.queryList(pubPickerDevice);
        return list;
    }
}
